using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Roots : MonoBehaviour
{
    public List<Feature> RootsFeatures = new List<Feature>();

    public int MaxExecuteNum = 10;
    public int ExecuteNum = 0;

    public void InitRootsByCard(Card card)
    {
        RootsFeatures = card.RootFeatures;
    }

    public void ExecuteRoots(int layer, int num)
    {
        if (ExecuteNum >= MaxExecuteNum)
            return;
        ExecuteNum++;

        if (RootsFeatures.Count > 0)
        {
             SpriteTextManager.NewEffectText( "Root传递", transform.position.x, transform.position.y, Color.white);
        }

        if (!GridManager.SubNodeDic.ContainsKey((layer, num)))
        {
            return;
        }
        var positions = GridManager.SubNodeDic[(layer, num)];
        List<Pawn> pawns = new List<Pawn>(); // 通过GridManager来找到所有被影响的pawn

        foreach (var pos in positions)
        {
            var node = GridManager.instance.GetGridNode(pos.layer, pos.number);
            if (node.Pawn != null)
                pawns.Add(node.Pawn);
        }

        foreach (var pawn in pawns)
        {
            pawn.FeatureMono.AddNewFeatureByRoots(this);
        }
    }
}
